package org.erp.spu.controller;

import org.erp.common.domain.Result;

import org.erp.spu.entity.dto.SpuModelAttributeDto;
import org.erp.spu.entity.vo.SpuModelAttrParentVo;
import org.erp.spu.service.SpuModelAttributeService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;

import java.util.List;

/**
 * 型号属性关系表(SpuModelAttribute)表控制层
 *
 * @author dingding
 * @since 2025-11-06 09:13:43
 */
@RestController
@RequestMapping("/model/attribute")
public class SpuModelAttributeController {

    @Resource
    private SpuModelAttributeService spuModelAttributeService;

    /**
     * 通过型号ID获取所有属性
     *
     * @param modelId
     * @return
     */
    @GetMapping("/getListByModelId")
    public Result<List<SpuModelAttrParentVo>> getListByModelId(@NotNull(message = "型号ID不能为空") Long modelId) {
        return Result.success(spuModelAttributeService.getListByModelId(modelId));
    }
    /**
     * 编辑型号属性关系
     *
     * @param spuModelAttributeDto
     * @return
     */
    @PostMapping("/edit")
    public Result<Boolean> edit(@RequestBody SpuModelAttributeDto spuModelAttributeDto) {
        boolean result=spuModelAttributeService.editSpuModelAttribute(spuModelAttributeDto);
        return result ? Result.success("添加成功") : Result.error("添加失败");
    }

//     /**
//     * 删除型号属性关系
//     * @deprecated
//     * @param spuModelAttributeDto
//     * @return
//     */
//    @PostMapping("/del")
//    public Result<Boolean> del(@RequestBody SpuModelAttributeDto spuModelAttributeDto) {
//        boolean result=spuModelAttributeService.removeById(spuModelAttributeDto.getId());
//        return result ? Result.success("删除成功") : Result.error("删除失败");
//    }





}
